package DEEPERsource.DEEPERsource.source.deeper;

import java.io.Serializable;

public class Protein implements Cloneable, Comparable, Serializable{
	
	private static final long serialVersionUID = 1L;
	
	//protein name bounds in the original sentence
	public int startOffset[];
	public int endOffset[];
	//protein name bounds in modified sentence
	public int startOffset_mod = -1;
	public int endOffset_mod = -1;
	//original name
	public String name;
	//modified name
	public String name_mod;
	public String type;
	//unique id (taken from PPI XML)
	public String id;
	
	@Override
	public Object clone(){
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public boolean includes(Protein p){
		if(startOffset[0]<=p.startOffset[0] &&
			endOffset[endOffset.length-1]>=p.endOffset[p.endOffset.length-1]){
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + endOffset[endOffset.length-1];
		result = PRIME * result + startOffset[0];
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Protein other = (Protein) obj;
		if (endOffset != other.endOffset)
			return false;
		if (startOffset != other.startOffset)
			return false;
		return true;
	}

	public int compareTo(Object arg0) {
		if(arg0 instanceof Protein){
			Protein p = (Protein) arg0;
			if(startOffset[0]>p.startOffset[0]){
				return 1;
			}else if(startOffset[0]<p.startOffset[0]){
				return -1;
			}
		}
		return 0;
	}
	
	public String toString(){
		return name+":"+name_mod;
	}
}
